<template>
  <div class="error-container">
    <h1 v-if="error.statusCode === 404">页面加载中...</h1>
    <h1 v-else>发生错误 {{ error.statusCode }}</h1>
    <button @click="handleError">返回首页</button>
  </div>
</template>

<script setup>
const props = defineProps({
  error: {
    type: Object,
    required: true
  }
})

const handleError = () => {
  clearError({ redirect: '/' })
}

// 客户端获取动态路由数据
if (process.client && props.error.statusCode === 404) {
  const route = useRoute()
  const { data } = await useAsyncData('dynamic-route', () => $fetch(`/api${route.path}`))
  
  if (data.value) {
    clearError()
    // 这里根据实际路由逻辑处理数据渲染
  }
}
</script>

<style scoped>
.error-container {
  text-align: center;
  padding: 2rem;
}
button {
  padding: 0.5rem 1rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
</style>